package com.borderbears.backend.actions;

import java.awt.Dialog.ModalityType;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.AbstractAction;

import com.borderbears.backend.BCBackendApp;
import com.borderbears.backend.connection.ConnectionManager;
import com.borderbears.backend.gui.ConfirmDialog;
import com.borderbears.backend.gui.ConnectionEditorForm;

public class AddConnectionAction extends AbstractAction {

	public AddConnectionAction(final String name) {
		super(name);

	}

	public AddConnectionAction() {
		super("Add Connection");
	}

	public void actionPerformed(final ActionEvent arg0) {
		final ConfirmDialog dialog = new ConfirmDialog(BCBackendApp
				.getApplication().getMainFrame(), "Add Connection",
				ModalityType.APPLICATION_MODAL);
		final ConnectionEditorForm panel = new ConnectionEditorForm();
		dialog.setContent(panel);
		// dialog.setContent(panel);
		dialog.addActonListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				ConnectionManager.getInstance().addConnection(panel.getConnection());
			}
		});
		dialog.setVisible(true);
	}
}
